var member_id  = ws = '';
document.addEventListener('plusready',function(){
	ws = plus.webview.currentWebview();
	member_id = plus.storage.getItem('id');
	console.log(apiRoot + "?act=member_order&op=order_list"+member_id);
	$.ajax({ 
		type:"post",
		url:apiRoot + "?act=member_order&op=order_list",
		data:{member_id:member_id,ordertype:2},
		dataType:'json', 
		success:function(info){
			console.log(JSON.stringify(info));
			if(info.code == 200){
				var html1 = '';
				var html2 = '';
				var html3 = '';
				var html4 = '';
				if(info.datas.order_group_list.length > 0){
					var flag1 = flag2 =flag3 = flag4 = 0;
					$.each(info.datas.order_group_list, function(k1,v1) {
						$.each(v1.order_list, function(k2,v2) {
							$.each(v2.extend_order_goods, function(k,v) {
								switch(v2.order_state){
									case '10' :
										flag1 = flag1+ 1;
										html1 += '<ul class="mui-table-view">' +
													 '<li class="mui-table-view-cell travel_details" data-order_id="'+ v2.order_id +'">'+
														 '<img class="mui-media-object mui-pull-left" src="'+ v.goods_image_url +'">'+
												 		 '<div class="mui-media-body">'+
													 		'<div class="mui-ellipsis-2">'+ v.goods_name +'</div>'+
													 		'<h5>'+										
													 			'<span><map class="mui-h5">￥</map>'+ v.goods_price +'</span>'+
																'<span>x'+ v.goods_num +'</span>'+
															'</h5>'+
															'<p class="mui-h6">'+
																'<span class="mui-pull-right">待付款</span>'+
															'</p>'+ 
														 '</div>'+
													 '</li>'+
												  '</ul>';
									break;
									case '20' :
										flag2 = flag2+ 1;
										html2 += '<ul class="mui-table-view">' +
													 '<li class="mui-table-view-cell travel_details" data-order_id="'+ v2.order_id +'">'+
															'<img class="mui-media-object mui-pull-left" src="'+ v.goods_image_url +'">'+
													 		'<div class="mui-media-body">'+
													 		'<div class="mui-ellipsis-2">'+ v.goods_name +'</div>'+
													 		'<h5>'+										
													 			'<span><map class="mui-h5">￥</map>'+ v.goods_price +'</span>'+
																'<span>x'+ v.goods_num +'</span>'+
															'</h5>'+
														 '</div>'+
													 '</li>'+
												  '</ul>';
									break;
									case '40' :
										flag3 = flag3+ 1;
										html3 += '<ul class="mui-table-view">' +
													 '<li class="mui-table-view-cell">'+
															'<img class="mui-media-object mui-pull-left travel_details" data-order_id="'+ v2.order_id +'" src="'+ v.goods_image_url +'">'+
													 		'<div class="mui-media-body">'+
													 		'<div class="mui-ellipsis-2">'+ v.goods_name +'</div>'+
													 		'<h5>'+										
													 			'<span><map class="mui-h5">￥</map>'+ v.goods_price +'</span>'+
																'<span>x'+ v.goods_num +'</span>'+
															'</h5>'+
															'<p class="mui-h6">'+
																'<span class="mui-pull-right travel_upl" data-order_id="'+ v2.order_id +'">删除</span>'+
															'</p>'+
														 '</div>'+
													 '</li>'+
												  '</ul>';
									break;   
									case '0' :
										flag4 = flag4+ 1;
										html4 += '<ul class="mui-table-view">' +
													 '<li class="mui-table-view-cell">'+
															'<img class="mui-media-object mui-pull-left travel_details" data-order_id="'+ v2.order_id +'" src="'+ v.goods_image_url +'">'+
													 		'<div class="mui-media-body">'+
													 		'<div class="mui-ellipsis-2">'+ v.goods_name +'</div>'+
													 		'<h5>'+										
													 			'<span><map class="mui-h5">￥</map>'+ v.goods_price +'</span>'+
																'<span>x'+ v.goods_num +'</span>'+
															'</h5>'+
															'<p class="mui-h6">'+
																'<span class="mui-pull-right travel_upl" data-order_id="'+ v2.order_id +'">删除</span>'+
															'</p>'+
														 '</div>'+
													 '</li>'+
												  '</ul>';
									break;
								}
							});
						});
					});
					var zt = '<div style="width: 80%;margin: 40px auto;text-align: center;font-size: 18px;">你还没有数据...</div>';
					if(flag1 > 0){
						$('#item1mobile .mui-scroll').html(html1);
					}else{
						$('#item1mobile .mui-scroll').html(zt);
					}
					if(flag2 > 0){
						$('#item2mobile .mui-scroll').html(html2);
					}else{
						$('#item2mobile .mui-scroll').html(zt);
					}
					if(flag3 > 0){
						$('#item3mobile .mui-scroll').html(html3);
					}else{
						$('#item3mobile .mui-scroll').html(zt);
					}
					if(flag4 > 0){
						$('#item4mobile .mui-scroll').html(html4);
					}else{
						$('#item4mobile .mui-scroll').html(zt);
					}
				}else{ 
					toast('没有更多数据！');
				}
			}
			//删除订单
			$('.travel_upl').on('click',function(){
				var _this = $(this);
				var order_id = _this.attr('data-order_id');
				order_receive(member_id,order_id);
			})
			//订单详情
			$('.travel_details').unbind('tap');
			$('.travel_details').on('tap',function(){
				var _this = $(this);
				var order_id = _this.attr('data-order_id');
				var nwaiting = plus.nativeUI.showWaiting();//显示原生等待框
				var webviewContent= plus.webview.create('./travel_off.html','travel_off.html',{},{order_id:order_id,spage:ws.id});//后台创建webview并打开show.html
				webviewContent.addEventListener("loaded", function() { //注册新webview的载入完成事件
			        nwaiting.close(); //新webview的载入完毕后关闭等待框
			        webviewContent.show("slide-in-right",500); //把新webview窗体显示出来，显示动画效果为速度200毫秒的右侧移入动画
			    }, false);
			})
			
			
		},
		error:function(e){
			console.log(JSON.stringify(e));
			toast('连接失败！');
		}
	});
	
},false)